package com.xja.manager.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xja.manager.base.PageResponse;
import com.xja.manager.bean.NursingProject;
import com.xja.manager.dto.NursingProjectDto;
import com.xja.manager.mapper.NursingProjectMapper;
import com.xja.manager.service.NursingProjectService;
import com.xja.manager.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 护理项目Service实现类
 */
@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    /**
     * 根据条件分页查询护理项目
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<NursingProjectVo> nursingProjects = nursingProjectMapper.selectByPage(name,status);
        Page<NursingProjectVo> pages = (Page<NursingProjectVo>) nursingProjects;
        return PageResponse.of(pages,NursingProjectVo.class);
    }


    /**
     * 新增护理项目
     *
     * @param nursingProjectDTO 护理项目数据传输对象
     */
    @Override
    public void add(NursingProjectDto nursingProjectDTO) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDTO, nursingProject);
//        System.out.println(nursingProject);
        nursingProjectMapper.insert(nursingProject);
    }

    /**
     * 根据ID查询护理项目
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo getById(Long id) {
        return nursingProjectMapper.selectById(id);
    }

    /**
     * 更新护理项目
     * @param nursingProjectDTO 护理项目数据传输对象
     */
    @Override
    public void update(NursingProjectDto nursingProjectDTO) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDTO, nursingProject);
        nursingProjectMapper.update(nursingProject);
    }

    /**
     * 启用或禁用状态
     * @param id ID
     * @param status 状态
     */
    @Override
    public void enableOrDisable(Long id, Integer status) {
        nursingProjectMapper.updateStatus(id, status);
    }

    /**
     * 删除护理项目
     * @param id 护理项目编号
     */
    @Override
    public void deleteById(Long id) {
        nursingProjectMapper.deleteById(id);
    }

    @Override
    public List<NursingProjectVo> listAll() {
        return nursingProjectMapper.listAll();
    }
}
